package dnl.persistence;

import au.com.bytecode.opencsv.CSVWriter;

import javax.sql.DataSource;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.sql.*;

/**
 * @author Daniel Orr
 */
public class TableToCsv {

    private JdbcToCsv jdbcToCsv;


    public TableToCsv(TableInfo tableInfo, Connection connection) {
        jdbcToCsv = new JdbcToCsv("select * from " + tableInfo.getTableName(), connection);
    }

    public TableToCsv(TableInfo tableInfo, DataSource dataSource) throws SQLException {
        this(tableInfo, dataSource.getConnection());
    }

    public void exportTo(File f) throws SQLException, IOException {
        jdbcToCsv.exportTo(f);
    }

}
